@@ -97,9 +97,15 @@ class MissionsController < ApplicationController |
||
| 97 | 97 |
def step_submission |
| 98 | 98 |
mission = Mission.friendly.find(params[:id]) |
| 99 | 99 |
agent = mission.mission_agents.friendly.find(params[:agent]) |
| 100 |
- submission = StepSubmission.new(step_submission_params) |
|
| 100 |
+ submission = StepSubmission.new |
|
| 101 |
+ agent.agent_steps.first.step_validations.each do |validation| |
|
| 102 |
+ if validation.validation_type == 'ValidationText' |
|
| 103 |
+ submission.submission_contents << SubmissionContent.new |
|
| 104 |
+ submission.submission_contents.last.build_submission('SubmissionText')
|
|
| 105 |
+ end |
|
| 106 |
+ end |
|
| 101 | 107 |
respond_to do |format| |
| 102 |
- if submission.save |
|
| 108 |
+ if submission.update(step_submission_params) |
|
| 103 | 109 |
format.html { redirect_to mission_agent_details_path(mission, agent), notice: (t 'mission.step_submission_confirmation') }
|
| 104 | 110 |
format.json { head :no_content }
|
| 105 | 111 |
else |
@@ -121,7 +127,7 @@ class MissionsController < ApplicationController |
||
| 121 | 127 |
end |
| 122 | 128 |
|
| 123 | 129 |
def step_submission_params |
| 124 |
- params.require(:step_submission).permit(:agent_step_id, :validated, :validated_by_id, :date_validated, :created_at, :updated_at, :language, :cover_img, :slug, :end_date, :submission_contents_attributes => [:submission_content_id, :submission_type, :created_at, :updated_at, :submission_attributes => [:submission_content_id, :content, :accepted, :validation_id, :created_at, :updated_at]]) |
|
| 130 |
+ params.require(:step_submission).permit(:agent_step_id, :validated, :validated_by_id, :date_validated, :created_at, :updated_at, :language, :cover_img, :slug, :end_date, :submission_contents_attributes => [:submission_content_id, :submission_type, :created_at, :updated_at]) |
|
| 125 | 131 |
end |
| 126 | 132 |
|
| 127 | 133 |
end |
@@ -2,6 +2,6 @@ class StepSubmission < ActiveRecord::Base |
||
| 2 | 2 |
belongs_to :agent_step |
| 3 | 3 |
belongs_to :validated_by, :class_name => "User" |
| 4 | 4 |
has_many :submission_contents, :dependent => :destroy |
| 5 |
- has_many :submissions, :through => :submission_contents |
|
| 5 |
+ has_many :submissions, :through => :submission_content |
|
| 6 | 6 |
accepts_nested_attributes_for :submission_contents, allow_destroy:true |
| 7 | 7 |
end |
@@ -2,4 +2,12 @@ class SubmissionContent < ActiveRecord::Base |
||
| 2 | 2 |
belongs_to :step_submission |
| 3 | 3 |
belongs_to :submission, polymorphic: true |
| 4 | 4 |
accepts_nested_attributes_for :submission, allow_destroy:true |
| 5 |
+ |
|
| 6 |
+ def build_submission(klass) |
|
| 7 |
+ if klass = 'SubmissionText' |
|
| 8 |
+ submission = SubmissionText.new |
|
| 9 |
+ self.submission_type = klass |
|
| 10 |
+ end |
|
| 11 |
+ self.submission = submission |
|
| 12 |
+ end |
|
| 5 | 13 |
end |
@@ -1,4 +1,5 @@ |
||
| 1 | 1 |
class SubmissionText < ActiveRecord::Base |
| 2 | 2 |
belongs_to :validation |
| 3 | 3 |
has_one :submission_content, :as => :submission, dependent: :destroy |
| 4 |
+ accepts_nested_attributes_for :submission_content, allow_destroy:true |
|
| 4 | 5 |
end |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 |
|
| 21 | 21 |
<%= f.fields_for :submission_contents, SubmissionContent.new, show_empty: true do |f| %> |
| 22 | 22 |
<%= f.alert_message "Please fix the errors below." %> |
| 23 |
- <%= f.fields_for :submission_text, SubmissionText.new, show_empty: true do |f| %> |
|
| 23 |
+ <%= f.fields_for :submission, SubmissionText.new, show_empty: true do |f| %> |
|
| 24 | 24 |
<%= f.text_field :content %> |
| 25 | 25 |
<% end %> |
| 26 | 26 |
<% end %> |